﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using HA.Data;
using HA.ModFlow.Infrastructure;
using HA.ModFlow.Controls.MT3DMSWindows;
using HA.ModFlow.Domain.DomainLayer;

namespace HA.ModFlow.Controls.Windows.MapData
{
    /// <summary>
    /// winConceptualModelProperty.xaml 的交互逻辑
    /// </summary>
    public partial class winConceptualModelProperty : Window
    {
        public winConceptualModelProperty(ConceptualModel cm,Units units)
        {
            InitializeComponent();

            this._cm = cm;

            this._units = units;
            //暂时认为model只是 modflow
            this._isManual = cm.ParentMapData.IsManualSetStressPeriod;

            gw =(GWModflow) (this._cm.Model as GWModflow).Clone ();

            this._stressPeriods = new List<StressPeriod>();
            foreach (StressPeriod item in cm.ParentMapData.StressPeriods.InnerList)
            {
                this._stressPeriods.Add((StressPeriod)item.Clone());
            }
        }

        bool _isManual;

        public bool IsManual
        {
            get { return _isManual; }
            set { _isManual = value; }
        }

        List<StressPeriod> _stressPeriods;

        Units _units;

        public Units Units
        {
            get { return _units; }
            set { _units = value; }
        }

        GWModflow gw;
        ConceptualModel _cm;

        public ConceptualModel Cm
        {
            get { return _cm; }
            set { _cm = value; }
        }



        private void ShowmGridData()
        {

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = gw;
            this.rbtnManual.DataContext = this;
            this.rbtnAuto.IsChecked = !_isManual;
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            Cm.Model = gw;
            Cm.ParentMapData.IsManualSetStressPeriod = this._isManual;
            Cm.ParentMapData.StressPeriods.InnerList.Clear();
            foreach (var item in this._stressPeriods)
            {
                Cm.ParentMapData.StressPeriods.InnerList.Add(item);
            }
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnDefinSpecies_Click(object sender, RoutedEventArgs e)
        {
            HA.ModFlow.Controls.MT3DMSWindows.winDefineSpecies win = new MT3DMSWindows.winDefineSpecies(gw.SpeList);
            if (win.ShowDialog().Value)
            {
                gw.SpeList.Clear();
                for (int i = 0; i < win.ArrySpecies.Count; i++)
                {
                    gw.SpeList.Add  ( win.ArrySpecies[i]);
                }

            }
        }

        private void btnButton_Click(object sender, RoutedEventArgs e)
        {
            winMT3DUnits winUnit = new winMT3DUnits(null, _units);
            winUnit.Owner = this;
            winUnit.ResizeMode = ResizeMode.NoResize;
            winUnit.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            winUnit.ShowDialog();
        }

        private void btnStrPeriod_Click(object sender, RoutedEventArgs e)
        {
            if (this._stressPeriods == null)
            {
                winStressPeriod winSPeriond = new winStressPeriod(this._cm.ParentMapData.StressPeriods.InnerList, _units);
                winSPeriond.Owner = this;
                winSPeriond.ResizeMode = ResizeMode.NoResize;
                winSPeriond.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                winSPeriond.ShowDialog();
                if (winSPeriond.DialogResult == true)
                {
                    this._stressPeriods = winSPeriond.StressPeriod;

                }
            }

            else
            {
                winStressPeriod winSPeriond = new winStressPeriod(this._stressPeriods, _units);
                winSPeriond.Owner = this;
                winSPeriond.ResizeMode = ResizeMode.NoResize;
                winSPeriond.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                winSPeriond.ShowDialog();
                if (winSPeriond.DialogResult == true)
                {
                    this._stressPeriods = winSPeriond.StressPeriod;

                }
            }
        }


    }
}
